package com.gmrz.uaf.common;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

public class Constants {
    private static final Logger LOG = LogManager.getLogger(Constants.class);
    public static final String PARAM_USERNAME = "userName";
    public static final String PARAM_POLICY = "policy";
    public static final String PARAM_STEPUP = "stepup";
    public static final String PARAM_TX_TEXT = "transactionText";
    public static final String PARAM_KEYID = "keyid";
    public static final String PARAM_AAID = "aaid";
    public static final String MFAC_REG_ID_FOR_PUSH = "notify";
    public static final String PN_AND_SENDER_ID_FOR_PUSH = "notify";
    public static final String STATUS_SUCCESS = "success";
    public static final String STATUS_FAILED = "failure";
    public static final Integer REST_RESPONSE_HTTP_ERROR_CODE = Integer.valueOf(400);
    public static final String UTF_8 = "UTF-8";
    public static final String CONST_CONTEXT = "context";
    public static final String CONST_APPLICATION = "application";
    public static final String CONST_FIDO_UAF = "fido+uaf";
    public static final String UAF_CONTENT_TYPE = "application/fido+uaf; charset=UTF-8";
    public static final String JSON_CONTENT_TYPE = "application/json; charset=UTF-8";
    public static final String SET_COOKIE = "Set-Cookie";
    public static final String EXPIRED = "Expired";
    public static final String SECOND_DEVICE_QR_CODE = "qrCode";
    public static final String SECOND_DEVICE_PUSH_NOTIFICATION = "push";
    public static final String JCE_X509_TYPE = "X.509";
    public static final String UAF_DBMS_NAME = "uaf.dbms.name";
    public static final String UAF_SECURITY_LEVEL_KEY = "uaf.security.level.";

    public static final String WHITE_LIST_KEY = "uaf.whiteList";
    public static final String POLICY_NAME_PREFIX = "POLICY_";
    public static final String APP_ID = "{APPID}";

    public static final String REDIS_TIME_OUT = "uaf.challenge.store.redis.client.request.timeout.seconds";
    public static final String REDIS_SERVERS = "uaf.challenge.store.redis.sentinel.servers";
    public static final String REDIS_DATA_NUMBER = "uaf.challenge.store.redis.server.database.number";
    public static final String REDIS_PASSWORD = "uaf.challenge.store.redis.server.encrypted.password";
    public static final String REDIS_MASTER_NAME = "uaf.challenge.store.redis.server.master.name";
    public static final String REDIS_ENCRYPT = "uaf.challenge.store.redis.server.should.encrypt.data";

    public static final String UAP_APP_ID = "uaf.application.id";

    public static final String UAP_AUTH_CONTEXT_CACHE_KEY = "uaf.auth.context.";
    public static final String UAP_REQ_CONTEXT_CACHE_KEY = "uaf.req.context.";
    public static final String UAP_UPDATE_CERT_CONTEXT_CACHE_KEY = "uaf.update.cert.context.";
    public static final String UAP_SIGNATURE_TYPE_CACHE_KEY = "uaf.signature.type.";
    public static final String UAP_UPDATE_CERT_STEP_CACHE_KEY = "uaf.update.cert.step.";
    public static final String UAP_UVS_MATCH_CACHE_KEY = "uaf.uvs.match";
    public static final String UAP_APP_ID_CACHE_KEY = "uaf.application.id";
    public static final String UAP_EXACT_MATCH_CACHE_KEY = "uaf.exact.match";

    public static final String UAP_ACTIVITY_CACHE_KEY = "uaf.activity.";

    public static final String UAP_SPEC_AAID = "uaf.challenge.store.redis.spec.aaid.";
    public static final String UAP_SPEC_ID = "uaf.challenge.store.redis.spec.id.";
    public static final String UAP_SPEC_LIST = "uaf.challenge.store.redis.spec.list";

    public static final String CACHE_VENDOR_ALLOW = "uaf.cache.vendor.allow.";//设备白名单
    public static final String CACHE_EQUIPMENT_FORBID = "uaf.cache.equipment.forbid.";//设备型号黑名单
    public static final String CACHE_DEVICE_FORBID = "uaf.cache.device.forbid.";//设备ID黑名单
    public static final int PERFORM_MODEL_LEVEL_1 = 1;
    public static final int PERFORM_MODEL_LEVEL_2 = 2;
    public static final int PERFORM_MODEL_LEVEL_3 = 3;
    public static final int PERFORM_MODEL_LEVEL_4 = 4;
    public static final String MAX_CERT_NUM = "9803976fe6fe4a769ac1e2113b55bd7b";
    public static final String CERT_DEVICE_TYPE = "96c217d86408471b971e98c41a402988";
    public static final String LOCK_KEY = "uaf.cert.lock";
    public static final int LOCK_EXPIRE_TIME = 10000;
    public static final String CERT_NUM = "uaf.cert.num";
    public static final String IS_REPEAT_1 = "1";
    public static final String IS_REPEAT_0 = "0";
    public static final String CERT_TRANSACTION_TEXT = "certTransactionText";
    public static final String CERT_TRANSACTION_SHOWFLAG = "certTransactionShowFlag";
    public static final String CERT_TRANSACTION_SHOWTEXT = "certTransactionShowText";
    public static final String CERT_TRANSACTION_ES_FLAG = "certTransactionEsFlag";
    public static final String CERT_TRANSACTION_ES_HASH = "certTransactionEsHash";
    public static final String CERT_TRANSACTION_EXT_TEXT = "certTransactionExtText";

    public static final String CERTIFICA = "certifica";
    public static final String DEVICE_MAX_NUM = "device.max.num";
    public static final String CERT_DN = "certDN";
    public static final String CERT_DN_JSON = "certDNJson";
    public static final String UAF_VENDOR_ACCEPT = "uaf.vendor.accept";
    public static final int TAG_CERT_AUTH_TRANSACTION = 35329;
    public static final int TAG_CERT_AUTH_TRADE_BASE = 35330;
    public static final int TAG_CERT_AUTH_TRADE_ISHOW = 35331;
    public static final int TAG_CERT_AUTH_TRADE_SHOWDATA = 35332;
    public static final int TAG_CERT_AUTH_TRADE_ISES = 35333;
    public static final int TAG_CERT_AUTH_TRADE_ESHASH = 35334;
    public static final String UAF_FIDO_LOG_SWITCH = "uaf.fido.log.switch";
    public static final int TRANSACTION_SHOW_LENGTH = 240;
    public static final int TRANSACTION_LENGTH = 2048;
    public static final String UAS_CONFIG_KEY_UAF_REG_STATUS = "uaf.reg.status";
    public static final String UAS_CONFIG_KEY_UAF_AUTH_STATUS = "uaf.auth.status";
    public static final String LOCK_VALUE = "uaf.cert.lock.value";
    public static final int LOCK_TIME = 90000;
    public static final String CONCURRENT_REQUEST_COUNT = "uaf.concurrent.request.count";
    public static final String AUTH_ERROR_COUNT = "uaf.auth.error.count.";

    public static final int CERT_STATUS_1 = 1;
    public static final int CERT_STATUS_2 = 2;
    public static final int CERT_STATUS_3 = 3;
    public static final int CERT_STATUS_4 = 4;

    public static final String UPDATE_CERT_STEP_1 = "1";
    public static final String UPDATE_CERT_STEP_2 = "2";
    public static final String UPDATE_CERT_STEP_3 = "3";

    public static final String FUNCTION_TYPE_ACTIVITY = "1";
    public static final String FUNCTION_TYPE_UPDATE_CERT = "1";

    public static final String CANCEL_REASON_TYPE_1 = "1";
    public static final String CANCEL_REASON_TYPE_2 = "2";
    public static final String CANCEL_REASON_TYPE_3 = "3";

    public static final String CANCEL_REASON_TYPE_4 = "4";

    public static final String CANCEL_REASON_TYPE_6 = "6";

    public static final String UAF_DELETE_LAST_AUTHENTICATOR = "uaf.delete.last.authenticator";
    public static final String UAF_DELETE_OTHER_AUTHENTICATOR = "uaf.delete.other.authenticator";
    public static final String UAF_NOT_ACTIVITY_AUTHENTICATOR = "uaf.not.activity.authenticator";
    public static final String UAF_ACTIVITY_ONLY_AUTHENTICATOR = "uaf.activity.only.authenticator";
    public static final String UAF_CERT_AUTH_EXT_HASH = "uaf.cert.auth.ext.hash";

    public static final int FIDO_LOG_EXTEND_TYPE_REQUEST = 1;
    public static final int FIDO_LOG_EXTEND_TYPE_RESPONSE = 2;

    public static final String UAF_RPID = "uaf.rpid";
    public static final String UAF_POLICY_CONFIG_KEY = "uaf.policy.config.";

    public static final String UAF_FORBID_ALLOW_CONCAT = "";
    public static final String UAF_FORBID_ALLOW_CONCAT_SPLIT = ",";
    public static final String UAF_FORBID_ALLOW_GLABAL_TENANT = "alltenant";

    public static final String UAF_CERT_AUTH_CUSTOMER_NAME_KEY = "customerName";
    public static String UAF_CERT_AUTH_CUSTOMER_NAME_VALUE = "fido";

    public enum DBMS {
        ORACLE("oracle"), POSTGRES("postgres"), MYSQL("dao"), DB2("db2");

        private String dbms;

        DBMS(String text) {
            this.dbms = text;
        }

        public String getText() {
            return this.dbms;
        }

        public static DBMS from(String dbmsName) {
            if (dbmsName != null) {
                for (DBMS d : values()) {
                    if (dbmsName.equalsIgnoreCase(d.dbms)) {
                        return d;
                    }
                }
            }
            throw new UAFRuntimeException("Invalid Database vendor provided.");
        }
    }

    public enum UAFV1AssertionTag {
        TAG_UAFV1_REG_ASSERTION(15873), TAG_UAFV1_AUTH_ASSERTION(15874), TAG_UAFV1_KRD(15875), TAG_UAFV1_SIGNED_DATA(
                15876), TAG_ATTESTATION_CERT(11781), TAG_SIGNATURE(11782), TAG_ATTESTATION_BASIC_FULL(
                15879), TAG_ATTESTATION_BASIC_SURROGATE(15880), TAG_KEYID(11785), TAG_FINAL_CHALLENGE(
                11786), TAG_AAID(11787), TAG_PUB_KEY(11788), TAG_COUNTERS(11789), TAG_ASSERTION_INFO(
                11790), TAG_AUTHENTICATOR_NONCE(11791), TAG_TRANSACTION_CONTENT_HASH(
                11792), TAG_VENDOR_SPECIFIC_EXTENSION(3839),

        AFI_RAW_USER_VERIFICATION_INDEX(259), AFI_USER_VERIFICATION_INDEX(260), AFI_UVS_USER_VERIFICATION_SET(261),

        TAG_CERT_TRANS_INFO_SIGN(21251),
        TAG_UNKNOWN(-1);

        private short value;

        UAFV1AssertionTag(int value) {
            this.value = ((short) value);
        }

        public short getTagValue() {
            return this.value;
        }

        public static UAFV1AssertionTag getTagForValue(int value) {
            for (UAFV1AssertionTag tag : values()) {
                if (tag.getTagValue() == value) {
                    return tag;
                }
            }
            Constants.LOG.debug("Unknown value[{}] of UAFV1AssertionTag, no match found",
                    Integer.valueOf(value));
            return TAG_UNKNOWN;
        }
    }

    public enum StatusCode {
        OK(1200), BAD_REQ(1400), UNACCEPTABLE_CONTENT(1401), INTERNAL_SERVER_ERROR(1500),UPDATECERT(1201);

        private int code;

        StatusCode(int code) {
            this.code = code;
        }

        public int getCode() {
            return this.code;
        }
    }

    public enum AuthSpec {
        ROOT_CERT(1, "root-certificate"), USER_VERIFICATION(2, "user-verification"), PNG_CHARACTERISTICS(3,
                "png-characteristics"), ATTESTATION_TYPE(4, "attestation-type"), PROTOCOL_VERSION(5,
                "protocol-version");

        private int id;
        private String name;

        public int getID() {
            return this.id;
        }

        public String getName() {
            return this.name;
        }

        AuthSpec(int p, String name) {
            this.id = p;
            this.name = name;
        }

        public static AuthSpec forName(String name) {
            for (AuthSpec t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid authencticator spec property: " + name);
        }

        public static AuthSpec forID(int id) {
            for (AuthSpec t : values()) {
                if (t.id == id) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid authencticator spec property ID: " + id);
        }
    }

    public enum ContentType {
        TEXT("text/plain"), PNG("image/png"), JSON("application/json");

        private String mimeType;

        ContentType(String name) {
            this.mimeType = name;
        }

        public String getMimeType() {
            return this.mimeType;
        }

        public static ContentType forName(String name) {
            for (ContentType t : values()) {
                if (t.mimeType.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid content type: " + name);
        }
    }

    public enum AuthenticatorSpecStatus {
        REVOKED(0), ACTIVE(1), DELETED(2), DISABLED(3);

        private int status = -1;

        AuthenticatorSpecStatus(int v) {
            this.status = v;
        }

        public int getStatus() {
            return this.status;
        }

        public static AuthenticatorSpecStatus forStatus(int v) {
            switch (v) {
                case 0:
                    return REVOKED;
                case 1:
                    return ACTIVE;
                case 2:
                    return DELETED;
                case 3:
                    return DISABLED;
            }
            return null;
        }
    }

    public enum AuthenticatorStatus {
        PENDING(0), ACTIVE(1), DELETED(2), DISABLED(3), UVI_REGISTERED(4);

        private int status = -1;

        AuthenticatorStatus(int v) {
            this.status = v;
        }

        public int getStatus() {
            return this.status;
        }

        public static AuthenticatorStatus forStatus(int v) {
            switch (v) {
                case 0:
                    return PENDING;
                case 1:
                    return ACTIVE;
                case 2:
                    return DELETED;
                case 3:
                    return DISABLED;
                case 4:
                    return UVI_REGISTERED;
            }
            return null;
        }
    }

    public enum TLVTag {
        TAG_UAFV1_REG_RESPONSE((short) 1), TAG_UAFV1_SIGN_RESPONSE((short) 2), TAG_UAFV1_KRD(
                (short) 3), TAG_UAFV1_SIGNEDDATA((short) 4), TAG_ATTESTATION_CERT((short) 5), TAG_SIGNATURE((short) 6);

        private short tag;

        public short getTag() {
            return this.tag;
        }

        TLVTag(short t) {
            this.tag = t;
        }
    }

    public enum AttestationType {
        ATTESTATION_BASIC_FULL(15879, "full-basic-attestation"), ATTESTATION_BASIC_SURROGATE(15880,
                "surrogate-basic-attestation");

        private String name;
        private int tag;

        AttestationType(int tag, String name) {
            this.name = name;
            this.tag = tag;
        }

        public String getName() {
            return this.name;
        }

        public int getTag() {
            return this.tag;
        }

        public static AttestationType forName(String name) {
            for (AttestationType t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid attestation name: " + name);
        }

        public static AttestationType forValue(int value) {
            for (AttestationType t : values()) {
                if (t.tag == value) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid attestation tag: " + value);
        }
    }

    public enum AssertionScheme {
        UAF_TLV("UAFV1TLV");

        private String name;

        AssertionScheme(String name) {
            this.name = name;
        }

        public String getName() {
            return this.name;
        }

        public static AssertionScheme forName(String name) {
            for (AssertionScheme t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid assertion scheme: " + name);
        }
    }

    public enum AttachmentHint {
        ATTACHMENT_HINT_INTERNAL(1L, "internal"), ATTACHMENT_HINT_EXTERNAL(2L, "external"),
        ATTACHMENT_HINT_WIRED(4L, "wired"), ATTACHMENT_HINT_WIRELESS(8L, "wireless"),
        ATTACHMENT_HINT_NFC(16L, "NFC"), ATTACHMENT_HINT_BLUETOOTH(32L, "bluetooth"),
        ATTACHMENT_HINT_NETWORK(64L, "network"), ATTACHMENT_HINT_READY(128L, "ready");

        private long hint;
        private String name;

        AttachmentHint(long h, String name) {
            this.hint = h;
            this.name = name;
        }

        public String getName() {
            return this.name;
        }

        public long getHint() {
            return this.hint;
        }

        public static AttachmentHint forName(String name) {
            for (AttachmentHint t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid attachment hint: " + name);
        }

        public static List<AttachmentHint> forValue(long f) {
            ArrayList<AttachmentHint> retval = new ArrayList<AttachmentHint>();

            for (AttachmentHint t : values()) {
                long tf = t.hint;
                if ((tf & f) == tf) {
                    retval.add(t);
                }
            }
            if (retval.isEmpty()) {
                return null;
            }
            return retval;
        }

        public static long computeHint(List<AttachmentHint> hints) {
            long retval = 0L;
            for (AttachmentHint f : hints) {
                retval |= f.hint;
            }
            return retval;
        }
    }

    public enum UserVerification {
        USER_VERIFY_PRESENCE(1L, "presence"), USER_VERIFY_FINGERPRINT(2L, "fingerprint"),
        USER_VERIFY_PASSCODE(4L, "passcode"), USER_VERIFY_VOICEPRINT(8L, "voiceprint"),
        USER_VERIFY_FACEPRINT(16L, "faceprint"), USER_VERIFY_LOCATION(32L, "location"),
        USER_VERIFY_EYEPRINT(64L, "eyeprint"), USER_VERIFY_PATTERN(128L, "pattern"),
        USER_VERIFY_HANDPRINT(256L, "handprint"), USER_VERIFY_NONE(512L, "none"),
        USER_VERIFY_ALL(1024L, "all");

        private long value;
        private String name;

        UserVerification(long value, String name) {
            this.value = value;
            this.name = name;
        }

        public long getValue() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }

        public static List<UserVerification> forValue(int value) {
            List<UserVerification> m = new ArrayList<UserVerification>();
            for (UserVerification mp : values()) {
                if ((value & mp.value) == mp.value) {
                    m.add(mp);
                    return m;
                }
            }
            throw new IllegalArgumentException("Invalid value of UserVerification tag[" + value + "]");
        }
    }

    public enum MatcherProtection {
        MATCHER_PROTECTION_SOFTWARE(1, "software"), MATCHER_PROTECTION_TEE(2, "tee"),
        MATCHER_PROTECTION_ON_CHIP(3, "chip");

        private int value;
        private String name;

        MatcherProtection(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }

        public static List<MatcherProtection> forValue(int value) {
            List<MatcherProtection> m = new ArrayList<MatcherProtection>();
            for (MatcherProtection mp : values()) {
                if ((value & mp.value) == mp.value) {
                    m.add(mp);
                    return m;
                }
            }
            throw new IllegalArgumentException("Invalid value of MatcherProtection tag[" + value + "]");
        }
    }

    public enum KeyProtection {
        KEY_PROTECTION_SOFTWARE(1, "software"), KEY_PROTECTION_HARDWARE(2, "hardware"),
        KEY_PROTECTION_TEE(4, "TEE"), KEY_PROTECTION_SECURE_ELEMENT(8, "secure_element"),
        KEY_PROTECTION_REMOTE_HANDLE(16, "remote");

        private int protection;
        private String name;

        public long getProtection() {
            return this.protection;
        }

        public String getName() {
            return this.name;
        }

        KeyProtection(int p, String name) {
            this.protection = p;
            this.name = name;
        }

        public static KeyProtection forName(String name) {
            for (KeyProtection t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid key protection: " + name);
        }

        public static List<KeyProtection> forValue(int f) {
            ArrayList<KeyProtection> retval = new ArrayList<KeyProtection>();

            for (KeyProtection t : values()) {
                int tf = t.protection;
                if ((tf & f) == tf) {
                    retval.add(t);
                }
            }
            if (retval.isEmpty()) {
                return null;
            }
            return retval;
        }

        public static long computeProtection(List<KeyProtection> protection) {
            int retval = 0;
            for (KeyProtection f : protection) {
                retval |= f.protection;
            }
            return retval;
        }
    }

    public enum SecureDisplay {
        SECURE_DISPLAY_ANY(1, "any"), SECURE_DISPLAY_PRIVILEGED_SOFTWARE(2, "software"),
        SECURE_DISPLAY_TEE(4, "TEE"), SECURE_DISPLAY_HARDWARE(8, "hardware"),
        SECURE_DISPLAY_REMOTE(16, "remote");

        private int display;
        private String name;

        public int getDisplay() {
            return this.display;
        }

        public String getName() {
            return this.name;
        }

        SecureDisplay(int d, String name) {
            this.display = d;
            this.name = name;
        }

        public static SecureDisplay forName(String name) {
            for (SecureDisplay t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid secure display: " + name);
        }

        public static List<SecureDisplay> forValue(int f) {
            ArrayList<SecureDisplay> retval = new ArrayList<SecureDisplay>();

            for (SecureDisplay t : values()) {
                int tf = t.display;
                if ((tf & f) == tf) {
                    retval.add(t);
                }
            }
            if (retval.isEmpty()) {
                return null;
            }
            return retval;
        }

        public static int computeDisplay(List<SecureDisplay> display) {
            int retval = 0;
            for (SecureDisplay f : display) {
                retval |= f.display;
            }
            return retval;
        }
    }

    public enum Operation {
        REG(1, "Reg"), AUTH(2, "Auth"), DEL(3, "Dereg"), UPDATE(4, "Update");

        private byte id;
        private String name;

        public int getID() {
            return this.id;
        }

        public String getName() {
            return this.name;
        }

        Operation(int p, String name) {
            this.id = ((byte) p);
            this.name = name;
        }

        public static Operation forName(String name) {
            for (Operation t : values()) {
                if (t.name.equals(name)) {
                    return t;
                }
            }
            throw new IllegalArgumentException("Invalid operation: " + name);
        }

        public static Operation forID(byte f) {
            for (Operation t : values()) {
                if (f == t.id) {
                    return t;
                }
            }
            return null;
        }
    }

    public enum AuthenticationMode {
        REG_MODE((byte) 1), AUTH_MODE((byte) 1), TXN_MODE((byte) 2);

        private byte value;

        AuthenticationMode(byte value) {
            this.value = value;
        }

        public byte getValue() {
            return this.value;
        }
    }

    public enum OPType {
        REGIST("00"), REGIST_SIGNLE("01"),REGIST_RESPONSE_NO_KEYID("02");
        private String opType;

        OPType(String opType) {
            this.opType = opType;
        }

        public String getOpType() {
            return opType;
        }
    }

    public enum AuthType {
        FINGERPRINT("00"), EYEPRINT("01"), FACEPRINT("02"), GESTUREPRINT("03"),
        REMOTE_FACEPRINT("10"), REMOTE_VOICEPRINT("11"), REMOTE_IDAUTH("12"), REMOTE_IDFACEAUTH("13"),
        REMOTE_OOBAUTH("14"), CERT_FINGERPRINT("20"), CERT_PIN("21"),CERT_FACEPRINT("22"),
        WEBAUTHN("30"),LOCATION_FINGER_PRINT("31");
        private String authType;

        AuthType(String authType) {
            this.authType = authType;
        }

        public String getAuthType() {
            return this.authType;
        }

        public static boolean isAuthType(String param) {
            for (AuthType a : values()) {
                if (a.getAuthType().equals(param)) {
                    return true;
                }
            }
            return false;
        }
    }

    public enum DeregFrom {
        CLIENT("00"), SERVER("01");
        private String from;

        DeregFrom(String from) {
            this.from = from;
        }

        public String getFrom() {
            return from;
        }
    }

    public enum Method {
        REG_STATUS("regStatus", 0), REG_INIT("regInit", 1), REG_FINISH("regFisnish", 2),
        AUTH_INIT("authInit", 3), AUTH_FINISH("authFinish", 4),
        DEREG_ONE("delete", 5), DEREG_ALL("deleteAll", 6),
        DEVICE_SUPPORT("deviceSupport", 7),
        DEVICE_LIST("deviceList", 8),
        IDAUTH_INIT("idauthInit", 9),
        IDAUTH_FINISH("idauthFinish", 10),
        ADD_UVI("addUvi", 11),
        OOBAUTH_INIT("oobAuthInit", 12),
        OOBAUTH_FINISH("oobAuthFinish", 13),
        OOB_GENERATE("oobGenerate", 14),
        OOB_STATUS("oobStatus", 15),
        GET_USER_INFO("getUserInfo", 16),
        GET_CERT_INFO("getCertInfo", 17),
        UPDATE_CERT_STATUS("updateCertStatus", 18),
        UPDATE_CERT("updateCert", 19),
        GET_USER_ALL_INFO("getUserAllInfo", 20),
        ACTIVATE_CERT("activateCert", 21),
        DEVICE_INFO("deviceInfo", 22),
        DEVICE_COSTED("deviceCosted", 23),
        REG_LISYT("regList", 24);


        private String methodName;
        private int operType;

        Method(String methodName, int operType) {
            this.methodName = methodName;
            this.operType = operType;
        }

        public String getMethodName() {
            return methodName;
        }

        public int getOperType() {
            return operType;
        }

        public static Method forMethod(String methodName) {
            for (Method m : values()) {
                if (m.getMethodName().equals(methodName)) {
                    return m;
                }
            }
            return null;
        }

        public static Method forMethodByOperType(int operType) {
            for (Method m : values()) {
                if (m.getOperType() == operType) {
                    return m;
                }
            }
            return null;
        }
    }

    public enum OOBStatus {
        NONE_SCANCODE(0), SCANCODE(1), APP_AUTH(2), SERVER_AUTH(3), AUTH_FAIL(4);

        //未扫码(0)、已扫码(1)、客户端已授权(2)、服务器已授权(3)、认证失败(4)
        private int status = -1;

        OOBStatus(int v) {
            this.status = v;
        }

        public int getStatus() {
            return this.status;
        }
    }

}
